import React, { Component } from 'react';

class App2 extends Component {

  state = {
    count: 1
  }

  fn = () => {
    /* this.setState({
      count: this.state.count + 1
    })
    this.setState({
      count: this.state.count + 1
    })
    this.setState({
      count: this.state.count + 1
    }) */
    this.setState(state => {
      return {
        count: state.count + 1
      }
    })
    this.setState(state => {
      return {
        count: state.count + 1
      }
    })
    this.setState(state => {
      return {
        count: state.count + 1
      }
    })
  }

  render() {
    return (
      <div>
        <h3>{this.state.count}</h3>
        <button onClick={this.fn}>自增</button>
      </div>
    );
  }
}

export default App2;
